using System;
using System.Collections;
using System.DirectoryServices;

namespace BEGDC.CC.Entity
{
	#region CustomerSurvey

	/// <summary>
	/// CustomerSurvey object for NHibernate mapped table 'CustomerSurvey'.
	/// </summary>
	[Serializable]
	public class CustomerSurvey : System.IComparable
		{
		#region Member Variables
		
		protected int _id;
		protected string _visitObjective;
		protected string _travelAgency;
		protected string _itinerary;
		protected string _duration;
		protected string _numberOfPerson;
		protected decimal _scoreA;
		protected decimal _scoreB;
		protected decimal _scoreC;
		protected string _commentA;
		protected string _commentB;
		protected string _commentC;
		protected bool _isSuggestion;
		protected Application _application;
		protected IList _surveyAnswers;
		protected static String _sortExpression = "Id";
		protected static SortDirection _sortDirection = SortDirection.Ascending;

		#endregion

		#region Constructors

		public CustomerSurvey() { }

		public CustomerSurvey( string visitObjective, string travelAgency, string itinerary, string duration, string numberOfPerson, decimal scoreA, decimal scoreB, decimal scoreC, string commentA, string commentB, string commentC, bool isSuggestion, Application application )
		{
			this._visitObjective = visitObjective;
			this._travelAgency = travelAgency;
			this._itinerary = itinerary;
			this._duration = duration;
			this._numberOfPerson = numberOfPerson;
			this._scoreA = scoreA;
			this._scoreB = scoreB;
			this._scoreC = scoreC;
			this._commentA = commentA;
			this._commentB = commentB;
			this._commentC = commentC;
			this._isSuggestion = isSuggestion;
			this._application = application;
		}

		#endregion

		#region Public Properties

		public int Id
		{
			get {return _id;}
			set {_id = value;}
		}

		public string VisitObjective
		{
			get { return _visitObjective; }
			set
			{
				if ( value != null && value.Length > 30)
					value = value.Substring(0, 30 );
				_visitObjective = value;
			}
		}

		public string TravelAgency
		{
			get { return _travelAgency; }
			set
			{
				if ( value != null && value.Length > 30)
					value = value.Substring(0, 30 );
				_travelAgency = value;
			}
		}

		public string Itinerary
		{
			get { return _itinerary; }
			set
			{
				if ( value != null && value.Length > 50)
					value = value.Substring(0, 50 );
				_itinerary = value;
			}
		}

		public string Duration
		{
			get { return _duration; }
			set
			{
				if ( value != null && value.Length > 20)
					throw new ArgumentOutOfRangeException("Invalid value for Duration", value, value.ToString());
				_duration = value;
			}
		}

		public string NumberOfPerson
		{
			get { return _numberOfPerson; }
			set
			{
				if ( value != null && value.Length > 20)
					throw new ArgumentOutOfRangeException("Invalid value for NumberOfPerson", value, value.ToString());
				_numberOfPerson = value;
			}
		}

		public decimal ScoreA
		{
			get { return _scoreA; }
			set { _scoreA = value; }
		}

		public decimal ScoreB
		{
			get { return _scoreB; }
			set { _scoreB = value; }
		}

		public decimal ScoreC
		{
			get { return _scoreC; }
			set { _scoreC = value; }
		}

		public string CommentA
		{
			get { return _commentA; }
			set
			{
				if ( value != null && value.Length > 1000)
					value = value.Substring(0, 1000 );
				_commentA = value;
			}
		}

		public string CommentB
		{
			get { return _commentB; }
			set
			{
				if ( value != null && value.Length > 1000)
					value = value.Substring(0, 1000 );
				_commentB = value;
			}
		}

		public string CommentC
		{
			get { return _commentC; }
			set
			{
				if ( value != null && value.Length > 1000)
					value = value.Substring(0, 1000 );
				_commentC = value;
			}
		}

		public bool IsSuggestion
		{
			get { return _isSuggestion; }
			set { _isSuggestion = value; }
		}

		public Application Application
		{
			get { return _application; }
			set { _application = value; }
		}

		public IList SurveyAnswers
		{
			get
			{
				if (_surveyAnswers==null)
				{
					_surveyAnswers = new ArrayList();
				}
				return _surveyAnswers;
			}
			set { _surveyAnswers = value; }
		}

        public static String SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

        public static SortDirection SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }
		#endregion
		
        #region IComparable Methods
        public int CompareTo(object obj)
        {
			if (!(obj is CustomerSurvey))
				throw new InvalidCastException("This object is not of type CustomerSurvey");
			
			int relativeValue;
			switch (SortExpression)
			{
				case "Id":
					relativeValue = this.Id.CompareTo(((CustomerSurvey)obj).Id);
					break;
				case "VisitObjective":
						relativeValue = ( this.VisitObjective != null ) ? this.VisitObjective.CompareTo(((CustomerSurvey)obj).VisitObjective) : -1;
					break;
				case "TravelAgency":
						relativeValue = ( this.TravelAgency != null ) ? this.TravelAgency.CompareTo(((CustomerSurvey)obj).TravelAgency) : -1;
					break;
				case "Itinerary":
						relativeValue = ( this.Itinerary != null ) ? this.Itinerary.CompareTo(((CustomerSurvey)obj).Itinerary) : -1;
					break;
				case "Duration":
						relativeValue = ( this.Duration != null ) ? this.Duration.CompareTo(((CustomerSurvey)obj).Duration) : -1;
					break;
				case "NumberOfPerson":
						relativeValue = ( this.NumberOfPerson != null ) ? this.NumberOfPerson.CompareTo(((CustomerSurvey)obj).NumberOfPerson) : -1;
					break;
				case "ScoreA":
					relativeValue = this.ScoreA.CompareTo(((CustomerSurvey)obj).ScoreA);
					break;
				case "ScoreB":
					relativeValue = this.ScoreB.CompareTo(((CustomerSurvey)obj).ScoreB);
					break;
				case "CommentA":
						relativeValue = ( this.CommentA != null ) ? this.CommentA.CompareTo(((CustomerSurvey)obj).CommentA) : -1;
					break;
				case "CommentB":
						relativeValue = ( this.CommentB != null ) ? this.CommentB.CompareTo(((CustomerSurvey)obj).CommentB) : -1;
					break;
				case "IsSuggestion":
					relativeValue = this.IsSuggestion.CompareTo(((CustomerSurvey)obj).IsSuggestion);
					break;
                default:
                    goto case "Id";
			}
            if (CustomerSurvey.SortDirection == SortDirection.Ascending)
				relativeValue *= -1;
			return relativeValue;
		}
		#endregion
	}

	#endregion
}
